package com.group.eams.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.group.eams.pojo.dto.AssetBorrowQueryDto;
import com.group.eams.pojo.dto.FixedAssetDetailQueryDto;
import com.group.eams.pojo.entity.AssetBorrow;
import com.group.eams.pojo.vo.AssetBorrowListVo;
import com.group.eams.pojo.vo.FixedAssetDetailListVo;
import com.group.eams.service.AssetBorrowService;
import com.group.pojo.dto.BatchDeleteDto;
import com.group.result.Result;
import com.group.result.ResultEnum;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 资产借用表(AssetBorrow)表控制层
 *
 * @author 
 * @since 2024-10-30 12:58:28
 */
@Controller
@RequestMapping("/assetBorrow")
@ResponseBody
public class AssetBorrowController  {
    /**
     * 服务对象
     */
    @Autowired
    private AssetBorrowService assetBorrowService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ApiOperation(value = "资产借用列表")
    public Result List(AssetBorrowQueryDto assetBorrowQueryDto){
        Page<AssetBorrowListVo> listVoPage = assetBorrowService.findAssetBorrowList(assetBorrowQueryDto);
        return Result.buildSuccess(listVoPage.getTotal(), listVoPage.getRecords());
    }

    @RequestMapping(value = "/find",method = RequestMethod.GET)
    @ApiOperation(value = "根据id查询资产借用信息")
    public Result find(@RequestParam Long id){
        AssetBorrow assetBorrow = assetBorrowService.getById(id);
        return Result.buildSuccess(assetBorrow);
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ApiOperation(value = "添加资产借用信息")
    public Result add(@RequestBody AssetBorrow assetBorrow){
        boolean result = assetBorrowService.save(assetBorrow);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ApiOperation(value = "修改资产借用信息")
    public Result update(@RequestBody AssetBorrow assetBorrow){
        boolean result = assetBorrowService.updateById(assetBorrow);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/delete",method = RequestMethod.GET)
    @ApiOperation(value = "删除资产借用信息")
    public Result add(@RequestParam Long id){
        boolean result = assetBorrowService.removeById(id);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }
    @RequestMapping(value = "/findAll",method = RequestMethod.GET)
    @ApiOperation(value = "查询所有资产借用信息")
    public Result findAll(){
        List<AssetBorrow> assetBorrowList = assetBorrowService.list();
        return Result.buildSuccess(assetBorrowList);
    }

    @RequestMapping(value = "/batchRemove",method = RequestMethod.POST)
    @ApiOperation(value = "批量删除信息")
    public Result batchRemove(@RequestBody BatchDeleteDto batchDeleteDto){
        boolean result = assetBorrowService.removeByIds(batchDeleteDto.getIds());
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/findByApplicationNum",method = RequestMethod.GET)
    @ApiOperation(value = "根据申请编号查询资产借用信息")
    public Result findByApplicationNum(@RequestParam String applicationNum){
        AssetBorrow assetBorrow = assetBorrowService.findByApplicationNum(applicationNum);
        return Result.buildSuccess(assetBorrow);
    }

    @RequestMapping(value = "/assetDetail",method = RequestMethod.GET)
    @ApiOperation(value = "资产借用明细")
    public Result assetList(FixedAssetDetailQueryDto fixedAssetDetailQueryDto){
        Page<FixedAssetDetailListVo> listVoPage = assetBorrowService.findByQueryDto(fixedAssetDetailQueryDto);
        return Result.buildSuccess(listVoPage.getTotal(), listVoPage.getRecords());
    }

    @RequestMapping(value = "/addBatch",method = RequestMethod.POST)
    @ApiOperation(value = "批量添加资产借用信息")
    public Result addBatch(@RequestBody List<AssetBorrow> assetBorrowList){
        boolean result = assetBorrowService.saveBatch(assetBorrowList);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/updateBatch",method = RequestMethod.POST)
    @ApiOperation(value = "批量修改资产借用信息")
    public Result updateBatch(@RequestBody List<AssetBorrow> assetBorrowList){
        boolean result = assetBorrowService.updateBatchById(assetBorrowList);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    //根据单号进行删除
    @RequestMapping(value = "/deleteByApplicationNum",method = RequestMethod.GET)
    @ApiOperation(value = "根据单号删除资产借用信息")
    public Result deleteByApplicationNum(@RequestParam String applicationNum){
        int result = assetBorrowService.deleteByApplicationNum(applicationNum);
        return result>0?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

}

